package com.wuye.dao;


import com.wuye.entity.Users;
import com.wuye.util.JdbcUtils;

import java.util.List;

/**
 * 用户数据业务层
 */
public class UsersDaoImpl implements UsersDao {

    /**
     * 查询所有的用户信息
     * @return
     */
    @Override
    public List<Users> getUsersAll() {
        String sql="select * from users ";
        List<Users> users= JdbcUtils.executeQuery(sql,null,Users.class);
        return users;
    }

    /**
     * 注册用户
     * @return
     */
    @Override
    public int saveUser(List<Object> users) {
        String sql="insert into users(uname,usex,uwork,uaddress,uphone,uemail,upwd) values(?,?,?,?,?,?,?) ";
        int count=JdbcUtils.executeUpdate(sql, users);
        return count;
    }

    /**
     * 修改用户
     * @param objects
     */
    @Override
    public int updateUser(List<Object> objects) {
        String sql="update users set uname=?,usex=?,uwork=?,uaddress=?,uphone=?,uemail=?,upwd=? where userid=? ";
        int count=JdbcUtils.executeUpdate(sql, objects);
        return count;
    }

    /**
     * 获取用户信息
     * @param userId
     * @return
     */
    @Override
    public Users getUserId(String userId) {
        String sql="select * from users where userid="+userId;
        List<Users> users= JdbcUtils.executeQuery(sql,null,Users.class);
        return users.get(0);
    }

    /**
     * 删除
     * @param objects
     */
    @Override
    public int deleteUser(List<Object> objects) {
        String sql="delete from users  where userid=? ";
        int count=JdbcUtils.executeUpdate(sql, objects);
        return count;
    }

    /**
     * 登录
     * @param objects
     * @return
     */
    @Override
    public Users login(List<Object> objects) {
        String sql="select * from users where uname=? and upwd=? ";
        List<Users> users= JdbcUtils.executeQuery(sql,objects,Users.class);
        if(users!=null&&users.size()>=1){
            return users.get(0);
        }
        return null;
    }



}
